package com.alibaba.csp.sentinel.dashboard.rule;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.config.ConfigService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

@Component("clusterServerNamespaceSetNacosPublisher")
public class ClusterServerNamespaceSetNacosPublisher implements DynamicRulePublisher<Set<String>> {

    @Resource
    private ConfigService configService;

    @Override
    public void publish(Set<String> rules) throws Exception {
        if (rules == null) {
            return;
        }
        configService.publishConfig(NacosConfigUtil.SERVER_NAMESPACE_SET_DATA_ID,
                NacosConfigUtil.GROUP_ID, JSON.toJSONString(rules));
    }
}
